package com.task.job;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil;
import org.springframework.stereotype.Component;

/**
 * 作者: LCG
 * 日期: 2020/7/28 11:20
 * 描述: 配置任务执行器444444 55555
 */

@Component
public class MyJob01 {


    @XxlJob("task02")
    public ReturnT<String> test001(String param){

        System.out.println("======task02======"+param);

        return ReturnT.SUCCESS;
     }



    /**
     * 2、分片广播任务
     */
    @XxlJob("shardingJobHandler")
    public ReturnT<String> shardingJobHandler(String param) throws Exception {

        // 分片参数
        ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
        XxlJobLogger.log("分片参数：当前分片序号 = {}, 总分片数 = {}", shardingVO.getIndex(), shardingVO.getTotal());

        //获取当前实例执行的分片
        int index = shardingVO.getIndex();

        if(index==0){
            System.out.println("====分片0====");
        }else if(index==1){
            System.out.println("====分片1====");
        }


        return ReturnT.SUCCESS;
    }

}
